using NUnit.Framework;
using PropertyExpression.Common;
using PropertyExpression.ControllableQuery.Test.Queries.T4;
using PropertyExpression.ControllableQuery.Test.Queries.StringBuilding;
using PropertyExpression.ControllableQuery.Toolkit;
using ModelPublicationSearchQuery = PropertyExpression.ControllableQuery.Test.Queries.T4.ModelPublicationSearchQuery;


namespace PropertyExpression.ControllableQuery.Test.QueryCheck
{
    [TestFixture]
    public class MainTest
    {
        [Test]
        public void ModelPublicationSearchQuery()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => new ModelPublicationSearchQuery(
                                    queryContext.CreateStringParam().AsOptionalValue(),
                                    OptionalValue.Nothing<IParam<string>>(),
                                    OptionalValue.Nothing<IParam<string>>()
                                    ),
                queryContext => new ModelPublicationSearchQuery(
                                    queryContext.CreateStringParam().AsOptionalValue(),
                                    queryContext.CreateStringParam().AsOptionalValue(),
                                    queryContext.CreateStringParam().AsOptionalValue()
                                    ),
                queryContext => new ModelPublicationSearchQuery(
                                    OptionalValue.Nothing<IParam<string>>(),
                                    OptionalValue.Nothing<IParam<string>>(),
                                    OptionalValue.Nothing<IParam<string>>()
                                    )
                );
        }

        [Test]
        public void PartLinkQuery()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => new PartLinkQuery(
                                    queryContext.CreateGuidParam(),
                                    queryContext.CreateGuidParam(),
                                    queryContext.CreateGuidParam(),
                                    new WithInnerPartLinkSwitcher(
                                        true,
                                        queryContext.CreateStringParam(),
                                        queryContext.CreateGuidParam())
                                    )
                );
        }

        [Test]
        public void TableValuedParameterQuery()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => new TableValuedParameterQuery(
                                    queryContext.CreateTableValuedParam<IPublicationCodeType>()
                                    )
                );
        }

        [Test]
        public void StringBuildingModelPublicationSearchQuery()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => new Queries.StringBuilding.ModelPublicationSearchQuery(
                                    queryContext.CreateStringParam().AsOptionalValue(),
                                    OptionalValue.Nothing<IParam<string>>(),
                                    OptionalValue.Nothing<IParam<string>>()
                                    ),
                queryContext => new Queries.StringBuilding.ModelPublicationSearchQuery(
                                    queryContext.CreateStringParam().AsOptionalValue(),
                                    queryContext.CreateStringParam().AsOptionalValue(),
                                    queryContext.CreateStringParam().AsOptionalValue()
                                    ),
                queryContext => new Queries.StringBuilding.ModelPublicationSearchQuery(
                                    OptionalValue.Nothing<IParam<string>>(),
                                    OptionalValue.Nothing<IParam<string>>(),
                                    OptionalValue.Nothing<IParam<string>>()
                                    )
                );
        }

        [Test]
        public void StringBuildingModelPublicationQuery()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => new ModelPublicationQuery(
                                    queryContext.CreateStringParam(),
                                    queryContext.CreateStringParam()
                                    )
                );
        }

        [Test]
        public void StringBuildingModelPublicationQuery2()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => new ModelPublicationQuery2(
                                    queryContext.CreateStringParam(),
                                    queryContext.CreateStringParam()
                                    )
                );
        }

        [Test]
        public void PublicationInsertQuery()
        {
            QueryChecker.CheckNonQueries(
                ConnectionString,
                queryContext => new PublicationInsertQuery(
                                    queryContext.CreateGuidParam(),
                                    queryContext.CreateIntParam()
                                    )
                );
        }

        [Test]
        public void PublicationDeleteQuery()
        {
            QueryChecker.CheckNonQueries(
                ConnectionString,
                queryContext => new PublicationDeleteQuery(
                                    queryContext.CreateGuidParam()
                                    )
                );
        }

        [Test]
        public void ModelPublicationQuery()
        {
            QueryChecker.CheckQueries(
                ConnectionString,
                queryContext => Query.ModelPublicationQuery(
                    queryContext.CreateStringParam(),
                    queryContext.CreateStringParam())
                );
        }

        private static string ConnectionString
        {
            get { return @"Data Source=(local);Initial Catalog=ControllableQuery;Integrated Security=True"; }
        }
    }
}